// radarPages/radarCenter/radarCenter.js
import {get_open_id, get_radar_list, user_login} from "../../utils/api.js";

const app = getApp()
var page = 1;
var selectedNews = false;
var newsList = [];
const util = require('../../utils/util')
const {
  formatTimeC
} = util

Page({

  /**
   * 页面的初始数据
   */
  data: {
    haveTap: 1, // 1: 可以点击 0：不可点击
    TaskShow: 0,
    SwitchId: 0,  // 0：跟进记录，1：行为统计
    behaviorCount:{},
    userInfo:{},
    unreadnum:0,
    unreadnum2:0,
    btuBottom:0,
    setInter:'',
    show_ajax_new:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('11111:',app.globalData.SwitchTabParams.v_id);
    if (options.share_id && options.carte_id) {
      app.globalData.shareOptions.share_id = options.share_id;
      app.globalData.shareOptions.carte_id = options.carte_id;
      app.globalData.SwitchTabParams.v_id = options.carte_id;
    }
    
  },

  ajax_new:function(){
    var that=this;
    that.data.setInter = setInterval(function () {
      var show_ajax_new = that.data.show_ajax_new;
      var radarInfo = that.data.radarInfo;
      var last_id = -1;
      if (app.globalData.userInfo.id > 0){
        if (radarInfo.length>0){
          last_id = radarInfo[0].id
        }
        let url = '/log_api/ajax_log_new';
        let params = {
          uid: app.globalData.userInfo.id,
          last_id: last_id
        }
        app.HttpPostSend(url, params, function (res) {
          
          if (res.msg != "success") {
            app.showTipMsg(res.msg);
          } else {
            
            if (res.data.id!=undefined && res.data.id>0){
              // newsList = [];
              // page = 1;
              // that.setData({
              //   radarInfo:[]
              // });
              // that.getRadarList(1);
              const timestamp = parseInt(new Date().getTime() / 1000)
              res.data.uid = res.data.uid
              if (!!res.data.username) {
                res.data.username = res.data.username
              } else {
                res.data.username = '';
              }
              if (!!res.data.logo) {
                res.data.avatar = res.data.logo
              } else {
                res.data.avatar = '';
              }
              switch (res.data.type) {
                // 1.点赞 2.收藏 3.转发 4. 商城 5.查看 6.聊天窗口
                case 1:
                  res.data.type = res.data.type
                  res.data.action = '点赞了'
                  res.data.able = '你的'
                  res.data.content = '门店帮扶系统'
                  res.data.description = ',你的人脉圈很受欢迎'

                  break;

                case 2:
                  res.data.type = res.data.type
                  res.data.action = '收藏了'
                  res.data.able = '你的'
                  res.data.content = '门店帮扶系统'
                  res.data.description = ',你的人脉圈很受欢迎'

                  break;

                case 3:
                  res.data.type = res.data.type
                  res.data.action = '转发了'
                  res.data.able = '你的'
                  res.data.content = '门店帮扶系统'
                  res.data.description = ',你的人脉圈正在扩散'
                  break;

                case 4:
                  res.data.type = res.data.type
                  res.data.action = '进入了'
                  res.data.able = '你的'
                  res.data.content = '商城'
                  break;

                case 5:
                  res.data.type = res.data.type
                  res.data.action = '查看了'
                  res.data.able = '你的'
                  res.data.content = '门店帮扶系统'
                  if (!!res.data.seeNum) {
                    res.data.description = '第' + res.data.seeNum + '次，强意向客户呦'
                  } else {
                    res.data.description = '第' + '' + '次，强意向客户呦'
                  }

                  break;

                case 6:
                  res.data.type = res.data.type
                  res.data.action = '进入聊天窗口'

                  break;

                case 7:
                  res.data.type = res.data.type
                  res.data.action = '访问了'
                  res.data.able = '你的'
                  res.data.content = '官网'

                  break;

                case 8:
                  res.data.type = res.data.type
                  res.data.action = '查看了'
                  res.data.able = '你的'
                  res.data.content = '动态'

                  break;

                case 9:
                  res.data.type = res.data.type
                  res.data.action = '播放了'
                  res.data.able = '你的'
                  res.data.content = '视频'

                  break;

                case 10:
                  res.data.type = res.data.type
                  res.data.action = '播放了'
                  res.data.able = '你的'
                  res.data.content = '语音'

                  break;

                case 11:
                  res.data.type = res.data.type
                  res.data.action = '访问了'
                  res.data.able = '你的'
                  res.data.content = '商城'

                  break;

                case 12:
                  res.data.type = res.data.type
                  res.data.action = '查看了'
                  res.data.able = '你的'
                  res.data.content = '广场分类'

                  break;

                case 13:
                  res.data.type = res.data.type
                  res.data.action = '浏览了'
                  res.data.able = '你的名为'
                  if (res.data.goodsName.length > 10) {
                    var goodsName = '"' + res.data.goodsName.slice(0, 10) + '...' + '"'
                  } else if (res.data.goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + res.data.goodsName + '"'
                  }
                  res.data.content = goodsName
                  res.data.able2 = '的商品'

                  break;

                case 14:
                  res.data.type = res.data.type
                  res.data.action = '进入了'
                  res.data.able = ''
                  res.data.content = '购买尽猎AI门店帮扶系统页面'

                  break;

                case 15:
                  res.data.type = res.data.type
                  res.data.action = '点击付款了'
                  res.data.able = '你的'
                  res.data.content = '尽猎AI门店帮扶系统'

                  break;

                case 16:
                  res.data.type = res.data.type
                  res.data.action = '成功购买了'
                  res.data.able = '你的'
                  res.data.content = '尽猎AI门店帮扶系统'

                  break;

                case 17:
                  res.data.type = res.data.type
                  res.data.action = '添加了'
                  res.data.able = '新的'
                  res.data.content = '地址'

                  break;

                case 18:
                  res.data.type = res.data.type
                  res.data.action = '提交了'
                  res.data.able = '新的'
                  res.data.content = '商品订单'

                  break;

                case 19:
                  if (res.data.goodsName == null) {
                    res.data.content = '商城支付了订单'
                  } else {
                    res.data.content = '商城支付了订单(订单金额：' + res.data.goodsName + ')'
                  }

                  res.data.type = res.data.type
                  res.data.action = '在'
                  res.data.able = '你的'

                  break;

                case 20:
                  res.data.type = res.data.type
                  res.data.action = '取消了'
                  res.data.able = '你的'
                  res.data.content = '商品订单'

                  break;

                case 21:
                  res.data.type = res.data.type
                  res.data.action = '点赞了'
                  res.data.able = '你的'
                  res.data.content = '动态'

                  break;
                case 22:
                  if (res.data.goodsName == null) {
                    res.data.content = '进店扫码支付了订单'
                  } else {
                    res.data.content = '进店扫码支付了订单(订单金额：' + res.data.goodsName + ')'
                  }

                  res.data.type = res.data.type
                  res.data.action = '在'
                  res.data.able = '你的'

                  break;
                case 30:
                  res.data.type = res.data.type
                  res.data.action = '保存了'
                  res.data.able = '你的'
                  res.data.content = '人脉海报'

                  break;
                case 31:
                  res.data.type = res.data.type
                  res.data.action = '添加'
                  res.data.able = '商品'
                  if (res.data.goodsName.length > 10) {
                    var goodsName = '"' + res.data.goodsName.slice(0, 10) + '...' + '"'
                  } else if (res.data.goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + res.data.goodsName + '"'
                  }
                  res.data.content = goodsName
                  res.data.able2 = '到购物车'

                  break;
                case 32:
                  res.data.type = res.data.type
                  res.data.action = '分享了'
                  res.data.able = '商品'
                  if (res.data.goodsName.length > 10) {
                    var goodsName = '"' + res.data.goodsName.slice(0, 10) + '...' + '"'
                  } else if (res.data.goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + res.data.goodsName + '"'
                  }
                  res.data.content = goodsName
                  res.data.able2 = '的链接'

                  break;
                case 33:
                  res.data.type = res.data.type
                  res.data.action = '保存了'
                  res.data.able = '商品'
                  if (res.data.goodsName.length > 10) {
                    var goodsName = '"' + res.data.goodsName.slice(0, 10) + '...' + '"'
                  } else if (res.data.goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + res.data.goodsName + '"'
                  }
                  res.data.content = goodsName
                  res.data.able2 = '的海报'

                  break;


                default:
                  break;
              }
              let aim_timestamp = parseInt(new Date(res.data.add_time * 1000).getTime() / 1000)
              res.data.add_time = formatTimeC(timestamp, aim_timestamp)
              // console.log(typeof radarInfo)
              // console.log(radarInfo.length)
              radarInfo.push(res.data);
              // that.sortData(radarInfo)
              that.setData({
                radarInfo: that.sortData(radarInfo)
              })
            }
           


          }
        });
      }
      
    }, 2000) //循环时间 这里是1秒
  },

  sortData:function (data) {
    //完成您的代码
    var that = this;
    data.sort((a, b) => b.id - a.id);
    data = that.unique_(data)
    console.log('>>>')
    console.log(data);
    console.log('>>>')
    //调用渲染视图
    return data;
        
  },
  unique_:function (arr1) {
    const res = new Map();
    return arr1.filter((a) => !res.has(a.uid) && res.set(a.uid, 1))
  },

  // 获取用户信息
  bindGetUserInfo: function (e) {
    const that = this
    let userInfo = e.detail.userInfo
    try {
      app.HttpPostSend(
        user_login, {
          openid: that.data.openid,
          username: userInfo.nickName,
          logo: userInfo.avatarUrl,
          sex: userInfo.gender
        },
        function (result_data) {
          if (result_data.msg != "success") {
            app.showTipMsg(result_data.msg);
          } else {
            app.globalData.authSettingUser = 1;
            let userInfo = {
              ...result_data.data
            }
            app.globalData.userInfo = userInfo
            wx.setStorage({
              key: 'userInfo',
              data: JSON.stringify(userInfo)
            })
            that.setData({
              TaskShow: 0,
              haveTap: 1,
              userInfo: userInfo
            })
            if (!!app.globalData.SwitchTabParams.v_id) {
              app.globalData.SwitchTabParams.v_id = app.globalData.userInfo.id
            }
            that.getRadarList(0);
            that.getUnRead();
          }
        })
    } catch (error) {

    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  //获取聊天未读数量
  getUnRead: function () {
    var that = this;
    var url2 = '/log_api/logReadNum';
    var params2 = {
      uid: app.globalData.userInfo.id
    };
    app.HttpGetSend(url2, params2, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        var count = res.data;
        if (count > 99) {
          count = 99;
        }
        that.setData({
          unreadnum: count
        })

        //获取聊天未读数量
        var url3 = '/chat_api/getReadNum';
        var params3 = {
          uid: app.globalData.userInfo.id
        };
        app.HttpGetSend(url3, params3, function (res) {
          if (res.msg != "success") {
            app.showTipMsg(res.msg);
          } else {
            var count = res.data;
            if (count > 99) {
              count = 99;
            }
            that.setData({
              unreadnum2: count
            })

            that.changeStatus();
          }
        });

      }
    });
  },

  //更改通知状态
  changeStatus:function(){
    const that = this;
    var url2 = '/weixin_api/updateTemplateResult';
    var params2 = {
      operatorId: that.data.userInfo.id
    };
    app.HttpGetSend(url2, params2, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    page = 1;
    selectedNews = false;
    newsList = [];
    const that = this
    wx.getSystemInfo({
      success: res => {
        // console.log('手机信息res'+res.model)
        let modelmes = res.model;
        if (modelmes.search('iPhone X') != -1) {
          that.setData({
            btuBottom: '42rpx'
          });
        }
      }
    })
    let openid = wx.getStorageSync('openid')
    if (openid) {
      app.globalData.openid = openid
      that.setData({
        openid,
      })
      let url = '/user_api/getInfoByOpenID';
      app.HttpPostSend(
        url, {
          openid: openid,
        },
        function (result_data) {
          if (result_data.msg != "success") {
            app.showTipMsg(result_data.msg);
          } else {
            if (!!result_data.data) {//如果后台有数据
              app.globalData.userInfo = {
                ...result_data.data
              }
              wx.setStorage({
                key: 'userInfo',
                data: JSON.stringify({
                  ...result_data.data
                })
              })
              that.setData({
                haveTap: 1,
                userInfo: result_data.data
              })
              if (!!app.globalData.SwitchTabParams.v_id) {
                app.globalData.SwitchTabParams.v_id = app.globalData.userInfo.id
              }
              that.getRadarList(0);
              that.getUnRead();
              that.ajax_new();
            } else {//如果后台无数据
              wx.login({
                success(res) {
                  let params = {
                    code: res.code
                  }
                  app.HttpGetSend(get_open_id, params, function (result) {
                    if (result.msg != "success") {
                      app.showTipMsg(result.msg);
                    } else {
                      app.globalData.openid = result.data.openid.openid;
                      wx.setStorage({
                        key: 'openid',
                        data: result.data.openid.openid
                      })
                      that.setData({
                        openid: result.data.openid.openid
                      })
                      that.setData({
                        TaskShow: 1,
                        openid: result.data.openid.openid
                      })
                    }
                  })
                }
              })
            }
          }
        })
    } else {
      wx.login({
        success(res) {
          let params = {
            code: res.code
          }
          app.HttpGetSend(get_open_id, params, function (result) {
            if (result.msg != "success") {
              app.showTipMsg(result.msg);
            } else {
              app.globalData.openid = result.data.openid.openid;
              wx.setStorage({
                key: 'openid',
                data: result.data.openid.openid
              })
              that.setData({
                openid: result.data.openid.openid
              })
              that.setData({
                TaskShow: 1,
                openid: result.data.openid.openid
              })
            }
          })
        }
      })
    }
  },

  // 获取雷达列表
  getRadarList: function(state) {
    wx.showLoading({
      title: '获取数据中',
    })
    const that = this
    app.HttpGetSend(
      get_radar_list, {
        operation_id: that.data.userInfo.id,
        page:page,
        page_size:10,
        state: state
      },
      function(res) {
        wx.hideLoading();
        // console.log(res)
        if (res.msg != "success") {
          app.showTipMsg(res.msg);
        } else {
          var radarInfo = res.data;
          if (radarInfo.length > 0) {
            const timestamp = parseInt(new Date().getTime() / 1000)
            for (let i = 0; i < radarInfo.length; i++) {
              radarInfo[i].uid = radarInfo[i].uid
              if (!!radarInfo[i].username) {
                radarInfo[i].username = radarInfo[i].username
              } else {
                radarInfo[i].username = '';
              }
              if (!!radarInfo[i].logo) {
                radarInfo[i].avatar = radarInfo[i].logo
              } else {
                radarInfo[i].avatar = '';
              }
              switch (radarInfo[i].type) {
                // 1.点赞 2.收藏 3.转发 4. 商城 5.查看 6.聊天窗口
                case 1:
                  radarInfo[i].type = radarInfo[i].type
                  // if (radarInfo[i].status == 1) {
                    radarInfo[i].action = '点赞了'
                    radarInfo[i].able = '你的'
                    radarInfo[i].content = '门店帮扶系统'
                    radarInfo[i].description = ',你的人脉圈很受欢迎'
                  // } else {
                  //   radarInfo[i].action = '取消点赞'
                  //   radarInfo[i].able = '你的'
                  //   radarInfo[i].content = '名片'
                  // }
                  break;

                case 2:
                  radarInfo[i].type = radarInfo[i].type
                  // if (radarInfo[i].status == 1) {
                    radarInfo[i].action = '收藏了'
                    radarInfo[i].able = '你的'
                  radarInfo[i].content = '门店帮扶系统'
                  radarInfo[i].description = ',你的人脉圈很受欢迎'
                  // } else {
                  //   radarInfo[i].action = '取消收藏'
                  //   radarInfo[i].able = '你的'
                  //   radarInfo[i].content = '名片'
                  // }
                  break;

                case 3:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '转发了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '门店帮扶系统'
                  radarInfo[i].description = ',你的人脉圈正在扩散'
                  break;

                case 4:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '进入了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '商城'
                  break;

                case 5:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '查看了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '门店帮扶系统'
                  if (!!radarInfo[i].seeNum) {
                    radarInfo[i].description = '第' + radarInfo[i].seeNum + '次，强意向客户呦'
                  } else {
                    radarInfo[i].description = '第' + '' + '次，强意向客户呦'
                  }

                  break;

                case 6:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '进入聊天窗口'

                  break;

                case 7:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '访问了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '官网'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 8:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '查看了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '动态'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 9:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '播放了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '视频'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 10:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '播放了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '语音'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 11:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '访问了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '商城'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 12:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '查看了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '广场分类'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 13:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '浏览了'
                  radarInfo[i].able = '你的名为'
                  if (radarInfo[i].goodsName.length>10){
                    var goodsName = '"' + radarInfo[i].goodsName.slice(0, 10) + '...' + '"'
                  } else if(radarInfo[i].goodsName.length == 0){
                    goodsName = ''
                  }else{
                    goodsName = '"' + radarInfo[i].goodsName + '"'
                  }
                  radarInfo[i].content = goodsName
                  radarInfo[i].able2 = '的商品'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 14:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '进入了'
                  radarInfo[i].able = ''
                  radarInfo[i].content = '购买尽猎AI门店帮扶系统页面'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 15:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '点击付款了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '尽猎AI门店帮扶系统'

                  break;

                case 16:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '成功购买了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '尽猎AI门店帮扶系统'

                  break;

                case 17:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '添加了'
                  radarInfo[i].able = '新的'
                  radarInfo[i].content = '地址'

                  break;

                case 18:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '提交了'
                  radarInfo[i].able = '新的'
                  radarInfo[i].content = '商品订单'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 19:
                  if (radarInfo[i].goodsName == null) {
                    radarInfo[i].content = '商城支付了订单'
                  }else{
                    radarInfo[i].content = '商城支付了订单(订单金额：' + radarInfo[i].goodsName +')'
                  }

                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '在'
                  radarInfo[i].able = '你的'
                  
                  break;

                case 20:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '取消了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '商品订单'

                  break;

                case 21:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '点赞了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '动态'

                  break;
                case 22:
                  if (radarInfo[i].goodsName == null) {
                    radarInfo[i].content = '进店扫码支付了订单'
                  } else {
                    radarInfo[i].content = '进店扫码支付了订单(订单金额：' + radarInfo[i].goodsName + ')'
                  }

                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '在'
                  radarInfo[i].able = '你的'

                  break;
                case 30:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '保存了'
                  radarInfo[i].able = '你的'
                  radarInfo[i].content = '人脉海报'

                  break;
                case 31:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '添加'
                  radarInfo[i].able = '商品'
                  if (radarInfo[i].goodsName.length > 10) {
                    var goodsName = '"' + radarInfo[i].goodsName.slice(0, 10) + '...' + '"'
                  } else if (radarInfo[i].goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + radarInfo[i].goodsName + '"'
                  }
                  radarInfo[i].content = goodsName
                  radarInfo[i].able2 = '到购物车'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                case 32:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '分享了'
                  radarInfo[i].able = '商品'
                  if (radarInfo[i].goodsName.length > 10) {
                    var goodsName = '"' + radarInfo[i].goodsName.slice(0, 10) + '...' + '"'
                  } else if (radarInfo[i].goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + radarInfo[i].goodsName + '"'
                  }
                  radarInfo[i].content = goodsName
                  radarInfo[i].able2 = '的链接'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;
                case 33:
                  radarInfo[i].type = radarInfo[i].type
                  radarInfo[i].action = '保存了'
                  radarInfo[i].able = '商品'
                  if (radarInfo[i].goodsName.length > 10) {
                    var goodsName = '"' + radarInfo[i].goodsName.slice(0, 10) + '...' + '"'
                  } else if (radarInfo[i].goodsName.length == 0) {
                    goodsName = ''
                  } else {
                    goodsName = '"' + radarInfo[i].goodsName + '"'
                  }
                  radarInfo[i].content = goodsName
                  radarInfo[i].able2 = '的海报'
                  // if (radarInfo[i].num > 3) {
                  //   radarInfo[i].description = '第' + radarInfo[i].num + '次，强意向客户呦'
                  // }
                  break;

                default:
                  break;
              }
              let aim_timestamp = parseInt(new Date(radarInfo[i].add_time * 1000).getTime() / 1000)
              radarInfo[i].add_time = formatTimeC(timestamp, aim_timestamp)

              newsList.push(radarInfo[i]);
            }

          }
          newsList = that.unique_(newsList)
          if (radarInfo.length < 10) {
            selectedNews = false;
          } else {
            selectedNews = true;
            page += 1;
          }

          that.setData({
            radarInfo: newsList
          })
          
          wx.hideLoading();
        }
      })
  },

  // 头部Tab切换
  swichHeadTab: function (e) {
    page = 1;
    selectedNews = false;
    newsList = [];
    const that = this
    const tap_switch_id = e.currentTarget.dataset.id
    const SwitchId = this.data.SwitchId
    if (tap_switch_id == SwitchId) {
      // console.log(true)
    } else {
      // console.log(SwitchId,tap_switch_id)
      let change = new Object()
      switch (tap_switch_id) {
        case 0:
          change['SwitchId'] = tap_switch_id
          that.getRadarList(0)
          break;

        case 1:
          change['SwitchId'] = tap_switch_id
          that.getuserCountData()
          // that.getAiRecord(that.data.options.uid)
          break;

        default:
          break;
      }
      that.setData(change)
    }
  },

  //获取个人名片数据统计数据
  getuserCountData:function(){
    const that = this;
    var url2 = '/user_api/behaviorCount';
    var params2 = {
      uid: app.globalData.userInfo.id
    };
    app.HttpGetSend(url2, params2, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
      } else {
        if(res.data){
          that.setData({
            behaviorCount: res.data
          })
        }
      }
    });
  },

  // 打开聊天列表页面
  goContactList: function () {
    const that = this
    wx.redirectTo({
      url: '/pages/contactList/contactList'
    })
  },

  // 打开个人名片页面
  goMyCarte: function () {
    const that = this
    wx.redirectTo({
      url: '/pages/myCarte/myCarte'
    })
  },

  // 返回名片首页
  goPerson: function () {
    const that = this
    wx.switchTab({
      url: '/pages/person/person',
    })
  },

  // 打开商品管理页面
  goManagePage: function () {
    const that = this
    console.log(that.data.userInfo);
    console.log(that.data.userInfo.is_staff);
    if (that.data.userInfo.is_staff == 1 && that.data.userInfo.is_boss == 0){
      app.showTipMsg('无权限');
    }else{
      wx.redirectTo({
        url: '/pages/manageGoods/manageGoods'
      })
    }
   
  },

  // 展示雷达用户信息
  showRadarUserInfo: function (e) {
    wx.navigateTo({
      url: '/radarPages/radarUserInfo/radarUserInfo?uid='+e.currentTarget.dataset.uid,
    })
  },

  // 展示行为统计详情
  showRadarOne: function (e) {
    var dtype = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/radarPages/radarOne/radarOne?dtype=' + dtype
    })
  },

  // 展示下线中心
  showBehaviorCenter: function (e) {
    wx.navigateTo({
      url: '/radarPages/behaviorCenter/behaviorCenter',
    })
  },

  // 打开个人统计信息页
  showPerson: function (e) {
    // console.log(e)
    wx.switchTab({
      url: '/pages/person/person',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    clearInterval(this.data.setInter);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    clearInterval(this.data.setInter);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (selectedNews == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      that.getRadarList(0);

    } else {
      wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function() {

  // }
})